<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title']=trim($_RQ['title']);
		$return['params']['title']=$_RQ['title'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$fields=array('id','title','logo','status');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_cmshouse_list',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'房产管理'),
			array('op'=>'shenhe','title'=>'待审核房产'),
			array('op'=>'edit','title'=>'添加房产'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'图片','type'=>'image'),								
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),
		),
		'search'=>array(
			array('name'=>'title','title'=>'名称','width'=>15,'type'=>'string'),
			array('name'=>'status','title'=>'状态','width'=>15,'type'=>'radio','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='shenhe'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>0);
	$fields=array('id','title','logo','status');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_cmshouse_list',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'房产管理'),
			array('op'=>'shenhe','title'=>'待审核房产'),
			array('op'=>'edit','title'=>'添加房产'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'图片','type'=>'image'),								
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),
		'action'=>array(	
			array('type'=>'href','op'=>'yes','title'=>'通过'),
			array('type'=>'href','op'=>'no','title'=>'驳回'),
		),
		),
		
	);
	$return['htmls']=$htmls;
	exi($return);
	}
if($_RQ['op']=='yes'){
		$id=intval($_RQ['id']);
		if($id){
			pdo_update('jy_cmshouse_list',array('status'=>1),array('id'=>$id));
			exi('已通过','','/list/');
		}else{
			exi('请先选择房产','','/list/');
		}
}
if($_RQ['op']=='no'){
		$id=intval($_RQ['id']);
		if($id){
			pdo_update('jy_cmshouse_list',array('status'=>2),array('id'=>$id));
			exi('已驳回','','/list/');
		}else{
			exi('请先选择房产','','/list/');
		}
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_cmshouse_list',array('id'=>$id));
	
	$item['lat_lng']=json_decode($item['lat_lng'],true);
	$item['hdp']=json_decode($item['hdp'],true);
	}else{
		$item=array();
	}
	
    $return['item']=$item;
	$return['ishow']=array('0'=>'不显示','1'=>'显示');
	$return['status']=array('0'=>'待审核','1'=>'已审核','2'=>'已驳回');
	$return['is']=array('0'=>'否','1'=>'是');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'全景设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'房产管理'),
			array('op'=>'shenhe','title'=>'待审核房产'),
			array('op'=>'edit','title'=>'添加房产')
		),
		'edit'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'logo','title'=>'首页图片','type'=>'image'),
			array('name'=>'huxing','title'=>'户型图','type'=>'image'),
			array('type'=>'array','name'=>'hdp','add_tip'=>'添加幻灯片',
				'list'=>array(
					array('type'=>'image','name'=>'image','title'=>'幻灯片'),	
					array('type'=>'string','name'=>'url','title'=>'url'),	
				),
				'details'=>array(
					array('type'=>'image','name'=>'image','title'=>'图片'),	
					array('type'=>'string','name'=>'url','title'=>'url'),	
				)
				),
			array('name'=>'lat_lng','title'=>'坐标','type'=>'lat_lng'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'type'),
			array('name'=>'louceng','title'=>'楼层','type'=>'string'),
			array('name'=>'mianji','title'=>'面积(㎡)','type'=>'string'),
			array('name'=>'junjia','title'=>'均价(元/㎡)','type'=>'string'),
			array('name'=>'price','title'=>'总价(万元)','type'=>'string'),
			array('name'=>'name','title'=>'联系人','type'=>'string'),
			array('name'=>'mobile','title'=>'联系电话','type'=>'string'),
			array('name'=>'desc','title'=>'详细','type'=>'text'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'ishow','title'=>'是否显示','type'=>'radio','options'=>'ishow'),
			array('name'=>'ishome','title'=>'是否首页显示','type'=>'radio','options'=>'is'),
			array('name'=>'ishot','title'=>'是否热门','type'=>'radio','options'=>'is'),
			)
			);
	$return['type']=array('1'=>'新房','2'=>'二手房');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写标题','');
	}
	if(!$postdata['logo']){
		exi('请上传图片','');
	}
	if(!$postdata['huxing']){
		exi('请填写户型','');
	}
	if(!$postdata['junjia']){
		exi('请填写均价','');
	}
	if(!$postdata['louceng']){
		exi('请填写楼层','');
	}
	$data=array_fields(array('status','title','type','logo','huxing','mianji','louceng','junjia','name','ishome','lat_lng','address','price','mobile','desc','ishot','hdp','ishow'),$postdata);
	$data['hdp']=json_encode($data['hdp']);
	$data['lat_lng']=json_encode($data['lat_lng']);
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_cmshouse_list',$data,array('id'=>$id));
				exi('设置成功！','','list');
			}else{
			    $data['uniacid']=$_SESSION['uniacid'];
				$data['createtime']=TIMESTAMP;
				pdo_insert('jy_cmshouse_list',$data);
				exi('添加成功！','','list');
				}
}
if($_RQ['op']=='del'){

	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_cmshouse_list',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_cmshouse_list',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>